package com.example.bomb;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.BmobSMS;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.LogInListener;
import cn.bmob.v3.listener.QueryListener;
import cn.bmob.v3.listener.SaveListener;

public class PhoneActivity extends AppCompatActivity {
    private EditText edtPhone;
    private EditText edtCode;
    private Button btn_getCode;
    private Button btn_reglog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_phone);

        edtCode = findViewById(R.id.edt_smscode);
        edtPhone = findViewById(R.id.edt_phone);
        btn_getCode = findViewById(R.id.btn_getCode);
        btn_getCode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String phone = edtPhone.getText().toString();
                BmobSMS.requestSMSCode(phone,"yanzhengma", new QueryListener<Integer>() {

                    @Override
                    public void done(Integer smsId,BmobException ex) {
                        if(ex==null){//验证码发送成功
                            Toast.makeText(PhoneActivity.this,"验证码已发送",Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        });

        btn_reglog = findViewById(R.id.btn_sign);
        btn_reglog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                BmobUser.signOrLoginByMobilePhone("11位手机号码",
                        "验证码", new LogInListener<BmobUser>() {
                    @Override
                    public void done(BmobUser bmobUser, BmobException e) {

                    }
                });
            }
        });

    }
}



